//
//  ATZViewController.swift
//  PassValueDemo
//
//  Created by MAC on 2020/8/21.
//  Copyright © 2020 MAC. All rights reserved.
//

import UIKit

class ATZViewController: UIViewController {

    var textF = UITextField()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let ymBtn_01 = UIButton()
        ymBtn_01.frame = CGRect(x: 50, y: 130, width: 220, height: 50)
        ymBtn_01.setTitle("发送通知，并返回传值", for: .normal)
        ymBtn_01.backgroundColor = .brown
        ymBtn_01.tag = 10001
        ymBtn_01.addTarget(self, action: #selector(tiaozhuanyemianclick(sender:)), for: .touchUpInside)
        view.addSubview(ymBtn_01)
        
        
        textF.frame = CGRect(x: 50, y: (ymBtn_01.frame.origin.y + ymBtn_01.frame.size.height) + 50, width: view.frame.size.width - 100, height: 50)
        textF.attributedPlaceholder = NSAttributedString(string: "请输入要传的值", attributes: [NSAttributedString.Key.foregroundColor : UIColor.yellow])
        textF.borderStyle = .line
        textF.textColor = .white
        textF.backgroundColor = .darkGray
        view.addSubview(textF)
        
    }
    //按钮的监听方法
    @objc func tiaozhuanyemianclick(sender:UIButton){

       //发送通知
        NotificationCenter.default.post(name: NSNotification.Name(rawValue: "NotificationTest"), object:self ,userInfo: ["post":textF.text!])
        //退出模态窗口
        self.dismiss(animated: true, completion: nil)
    }
    //最后这里一定要记得移除通知
    deinit {
        print("移除通知")
        NotificationCenter.default.removeObserver(self)
    }
}
